{% extends 'base.html' %}
{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header">
            <h2>{{ document.title }}</h2>
        </div>
        <div class="card-body">
            <div class="row mb-3">
                <div class="col-md-6">
                    <p><strong>分类:</strong> {{ document.category }}</p>
                    <p><strong>状态:</strong> {{ document.status }}</p>
                </div>
                <div class="col-md-6">
                    <p><strong>创建者:</strong> {{ document.created_by }}</p>
                    <p><strong>创建时间:</strong> {{ document.created_at }}</p>
                </div>
            </div>
            <div class="mb-3">
                <h5>内容</h5>
                <div class="border p-3">
                    {{ document.content|safe }}
                </div>
            </div>
            <div class="mb-3">
                <h5>文件</h5>
                {% if document.file %}
                <a href="{{ document.file.url }}" class="btn btn-primary" download>下载文件</a>
                {% else %}
                <p>无附件</p>
                {% endif %}
            </div>
            <div class="mb-3">
                <h5>标签</h5>
                <p>{{ document.tags }}</p>
            </div>
            <div class="mb-3">
                <h5>描述</h5>
                <p>{{ document.description }}</p>
            </div>
        </div>
    </div>
    
    <div class="card mt-4">
        <div class="card-header">
            <h3>版本历史</h3>
        </div>
        <div class="card-body">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>版本号</th>
                        <th>修改者</th>
                        <th>修改时间</th>
                        <th>变更内容</th>
                    </tr>
                </thead>
                <tbody>
                    {% for version in document.documentversion_set.all %}
                    <tr>
                        <td>{{ version.version_number }}</td>
                        <td>{{ version.created_by }}</td>
                        <td>{{ version.created_at }}</td>
                        <td>{{ version.changes }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    
    <div class="mt-3">
        <a href="{% url 'doc_manager:document_list' %}" class="btn btn-secondary">返回列表</a>
        <a href="{% url 'doc_manager:document_update' document.id %}" class="btn btn-primary">编辑</a>
    </div>
</div>
{% endblock %}